<%@ page language="java" pageEncoding="utf-8"%>
<%@taglib prefix="s" uri="/struts-tags"%>
${aier_doctype}
<html <s:property value="aier_html_xmlns" escape="false"/>>
<head>
<meta http-equiv="Content-Type" content="${aier_content_type}" />
<title><s:property value="ev_title" /></title>
<meta name="keywords" content="${aier_keyworks}" />
<meta name="description" content="${aier_description}" />
<link href="${aier_css_url}jq/jq.css" rel="Stylesheet" />
<link rel="stylesheet" href="${aier_css_url}${aier_jqui_css}/ui.css" />
<link rel="stylesheet" href="${aier_css_url}social/module/jq-msg.css" />
<link rel="stylesheet" href="${aier_css_url}comm/text.css" />
<link rel="stylesheet" href="${aier_css_url}admin/admin.css" />

<script type="text/javascript" src="${aier_js_url}j.js"></script>
<script type="text/javascript" src="${aier_js_url}b.js"></script>
<script type="text/javascript" src="${aier_js_url}jp/msg.js"></script>
<script type="text/javascript" src="${aier_js_url}jp/1.js"></script>
<script type="text/javascript" src="${aier_js_url}lib/afu.js"></script>
<script type="text/javascript" src="${aier_js_url}jp/hh/ui.js"></script>
<script type="text/javascript" src="${aier_js_url}lib/block.js"></script>
<script type="text/javascript" src="${aier_js_url}lib/arrayList.js"></script>
<script type="text/javascript" src="${aier_js_url}97/WdatePicker.js"></script>
<script type="text/javascript" src="${aier_js_url}jc/cj.js"></script>
<script type="text/javascript" src="${aier_js_url}jq/jq.js"></script>
<script type="text/javascript" src="${aier_js_url}jq/cn.js"></script>
<script type="text/javascript" src="${aier_js_url}comm/text.js"></script>
</head>
<script type="text/javascript">
$(document).ready(function(){
    $("#userinfo").jqGrid({                
        url:'${aier_url}${aier_urijs}buy_searchUserList${aier_suffix}',                
        datatype:"json",                
        mtype:'GET',
        height:'230',
        width:'960',              
        colNames:['帐号','服务终止日期','充值','取消服务','转移服务','uid'],                
        colModel:[                    
        {name:'account',index:'account',width:120,align:'center'},                    
        {name:'edate',index:'edate',width:120,align:'center'},
        {name:'revoked',index:'revoked',width:120,align:'center'},
        {name:'revoked1',index:'revoked1',width:120,align:'center'},
        {name:'revoked2',index:'revoked2',width:120,align:'center'},
        {name:'uid',index:'uid',hidden : true}
        ],
        //autowidth:true,
        jsonReader: {
            root:"userList",
            page: "page",
            total: "page_count",
            records : "count",
            repeatitems: false
        },
        pager: jQuery("#userpage"),
        prmNames : {page:"page",sort: "sort"},
        rowNum: 10,
        sortname: 'sid',
        hidegrid: false,
        sortorder: 'asc',
        viewrecords: true,
        caption: '充值服务',
        gridComplete:function(){
            var ids=jQuery("#userinfo").jqGrid('getDataIDs');
            for(var i=0; i<ids.length; i++){
                var id=ids[i]; 
                var re = "<a href='javascript:;' class='jqtrow' onclick='buyService(" + id + ")'>充值</a>";
                var re1 = "<a href='javascript:;' class='jqtrow' onclick='cancelService(" + id + ")'>取消服务</a>";
                var re2 = "<a href='javascript:;' class='jqtrow' onclick='transferService(" + id + ")'>转移服务</a>";
                jQuery("#userinfo").jqGrid('setRowData', ids[i], { revoked: re,revoked1: re1,revoked2: re2});
            }
        }
    }).navGrid("#userpage", { edit: false, add: false, del: false, search: false });
}); 
</script>
<body style="background-color: #EEF2FB;">
    
    <div style="background-color: #EEF2FB;width: 100%;height: 700px; ">
       
         <div id="tabs">
             <ul>
                 <li><a href="#tabs-1">充值服务</a></li>
             </ul>
             <div id="tabs-1" style="height: 500px;">
                 <div class="d_content">
                    <div class="d_scnOut">
                        <div class="d_scname" style="margin-left: 0px;">
                            <label for="name">帐号: </label>
                        </div>
                        <div class="d_sctext">
                            <input type="text" id="account" />
                        </div>
                    </div>
                    <div style="margin-left: 600px;margin-top: -47px;">
                        <button onclick="search();"
                            class="ui-button ui-widget ui-state-default ui-corner-all ui-button-text-only"
                            role="button" aria-disabled="false">
                            <span class="ui-button-text">查询</span>
                        </button>
                    </div>
                    
                     <!-- 表格 -->
                     <div style="margin-left: 0px;margin-top: 0px;">
                         <table id="userinfo"></table>
                         <div id="userpage"></div>
                     </div>
                            
				</div>
				
				<!-- 弹出层内容 充值-->
                <div id="buy_service" title="充值" style="display: none;">
                    <div class="d_scnOut" style="margin-top: 10px;">
                        <div class="d_scname" style="font-size: 14px;">
                            <label>帐号:</label>
                        </div>
                        <div class="d_sctext" style="font-size: 14px;">
                            <span id="uaccount" class="txt_scname"></span>
                        </div>
                    </div>
                    <div class="d_scnOut" style="margin-top: 10px;">
                        <div class="d_scname" style="font-size: 14px;">
                            <label>充值方式选择:</label>
                        </div>
                    </div>
                    
                    <div class="d_scnOut">
                        <div style="font-size: 14px;margin-left: 50px;" >
                            <input name="method" type="radio" id="r_month" value="1" checked="checked"><label>按月充值:</label>
                                <input id="month"><label>个月</label>
                        </div>
                    </div>
                    <div class="d_scnOut">
                        <div style="font-size: 14px;margin-left: 50px;">
                            <input name="method" type="radio" id="r_day" value="0"><label>按天充值（选择服务终止日期）:</label>
                            <input type="text" id="day" class="txt_scname"
                                            onfocus="WdatePicker({skin:'whyGreen',dateFmt:'yyyy-MM-dd'})"
                                            class="Wdate">
                        </div>
                    </div>
                            
                    <button style="margin-top: 30px;margin-left: 200px" onclick="buy();"
                            class="ui-button ui-widget ui-state-default ui-corner-all ui-button-text-only"
                            role="button" aria-disabled="false">
                            <span class="ui-button-text">充值</span>
                    </button>
                </div>
                
                <!-- 弹出层内容 转移服务-->
                <div id="transfer_service" title="转移服务" style="display: none;">
                    <div class="d_scnOut" style="margin-top: 10px;">
                        <div class="d_scname" style="font-size: 14px;">
                            <label>旧的帐号:</label>
                        </div>
                        <div class="d_sctext" style="font-size: 14px;">
                            <span id="taccount" class="txt_scname"></span>
                        </div>
                    </div>
                    <div class="d_scnOut" style="margin-top: 10px;">
                        <div class="d_scname" style="font-size: 14px;">
                            <label>新的帐号:</label>
                        </div>
                        <div class="d_sctext" style="font-size: 14px;">
                            <input type="text" id="naccount">
                        </div>
                    </div>
                            
                    <button style="margin-top: 30px;margin-left: 130px" onclick="transfer();"
                            class="ui-button ui-widget ui-state-default ui-corner-all ui-button-text-only"
                            role="button" aria-disabled="false">
                            <span class="ui-button-text">转移服务</span>
                    </button>
                </div>
                
                <div id="deleteConfirm" style="display: none;" title="删除">
                        <p>确认要取消该用户的服务吗?</p>
                </div>
                
			</div>
        </div>
	</div>

	<script type="text/javascript">
		$("#tabs").tabs();
		var uid;
		// 弹出层
	    $(function() {
	        $("#buy_service").dialog({
	            //背景变暗
	            modal: true,
	            autoOpen : false,
	            show : "blind",
	            width : "500",
	            height : "400"
	        });
	    
	    });
	    $(function() {
            $("#transfer_service").dialog({
                //背景变暗
                modal: true,
                autoOpen : false,
                show : "blind",
                width : "400",
                height : "350"
            });
        
        });
	
	  // 根据条件查询用户列表 
      function search(){
         jQuery("#userinfo").jqGrid('setGridParam',{url:'${aier_url}${aier_urijs}buy_searchUserList${aier_suffix}'+"?account="+$("#account").val(),page:1}).trigger("reloadGrid");
     }
     // 弹出充值对话框
     function buyService(id) {
         uid = jQuery("#userinfo").jqGrid('getRowData', id).uid;
         $("#uaccount").html(jQuery("#userinfo").jqGrid('getRowData', id).account);
         $("#buy_service").dialog("open");
     }
     // 充值
     function buy() {
    	 var method = 1;
    	 var edate = null;
    	 if ($('#r_month').attr("checked") == "checked") {
             method = 1;
             edate = $("#month").val();
             if (isnull(edate)) {
            	 $().message("请输入月份数!");
            	 return;
             }
             if (!isNum(edate)) {
            	 $().message("请输入有效数字!");
                 return;
             }
             
         } else {
             method = 2;
             edate = $("#day").val();
             if (isnull(edate)) {
                 $().message("请输入服务终止日期!");
                 return;
             }
         }
    	 var fun = function(data) {
             if(1==data.s){
            	 $("#month").val("");
            	 $("#day").val("");
            	 $('#r_month').attr("checked","checked");
                 $().message("充值成功!");
                 $("#userinfo").trigger("reloadGrid");
                 $("#buy_service").dialog("close");
             }else{
                 $().message("充值失败,请稍后再试!");
             }
         };
         exeAjax(ajaxUrl("${aier_url}${aier_urijs}buy_buyServiceByUser${aier_suffix}"), fun, 
         {
        	 "uid" :uid,
        	 "method":method,
        	 "edate":edate
         });
     }
     
     // 取消服务
     function cancelService(id) {
    	 uid = jQuery("#userinfo").jqGrid('getRowData', id).uid;
    	 
         $(function() {
             $("#deleteConfirm").dialog(
                 {
                     //背景变暗
                     modal : true,
                     autoOpen : false,
                     show : "fade",
                     hide : "fade",
                     width : "340",
                     height : "220",
                     buttons : {
                         "确定" : function() {
                        	 var fun = function(data) {
                                 if(1==data.s){
                                     $("#userinfo").trigger("reloadGrid");
                                     $("#deleteConfirm").dialog("close");
                                 }else{
                                     $().message("取消服务失败,请稍后再试!");
                                     $("#deleteConfirm").dialog("close");
                                 }
                             };
                             exeAjax(ajaxUrl("${aier_url}${aier_urijs}buy_cancelServiceByUser${aier_suffix}"), fun, 
                             {
                                 "uid" :uid
                             });
                         },
                         "取消" : function() {
                             $(this).dialog("close");
                         }
                 }
             });
             $("#deleteConfirm").dialog("open");
         });
     }
     
     // 弹出转移服务的对话框
     function transferService(id) {
    	 uid = jQuery("#userinfo").jqGrid('getRowData', id).uid;
         $("#taccount").html(jQuery("#userinfo").jqGrid('getRowData', id).account);
         $("#naccount").val("");
         $("#transfer_service").dialog("open");
     }
     
     // 转移服务
     function transfer() {
         var naccount = $("#naccount").val();
         if (isnull(naccount)) {
             $().message("请输入新的帐号!");
             return;
         }
         if (!check_mobile(naccount)) {
        	 $().message("请输入有效的帐号!");
             return;
         }
         var fun = function(data) {
             if(1==data.s){
                 $().message("转移服务成功!");
                 $("#userinfo").trigger("reloadGrid");
                 $("#transfer_service").dialog("close");
             }else if(10001==data.s) {
            	 $().message("要转移服务的用户没有购买服务!");
             }else if(10002==data.s) {
                 $().message("要转移服务的用户服务已过期!");
             }else if(10003==data.s) {
                 $().message("新用户不存在!");
             }else{
                 $().message("转移服务失败,请稍后再试!");
             }
         };
         exeAjax(ajaxUrl("${aier_url}${aier_urijs}buy_transferServiceByUser${aier_suffix}"), fun, 
         {
             "uid" :uid,
             "account":naccount
         });
     } 
     
	</script>
</body>
</html>